package e

import "github.com/astaxie/beego/validation"

var MsgFlags = map[int]string{
	SUCCESS:"OK",
	ERROR: "fail",
	ERROR_NO_USER: "用户不存在或密码错误",
	INVALID_PARAMS: "请求参数错误",
	ERROR_EXIST_TAG: "已存在该标签名称",
	ERROR_NOT_EXIST_TAG:"标签不存在",
	ERROR_NOT_EXIST_ARTICLE: "该文章不存在",
	ERROR_AUTH_CHECK_TOKEN_FAIL: "token鉴权失败",
	ERROR_AUTH_CHECK_TOKEN_TIMEOUT: "token超时",
	ERROR_AUTH: "token错误",
	ERROR_AUTH_TOKEN: "token生成错误",
	ERROR_UPLOAD_SAVE_IMAGE_FAIL : "保存图片失败",
	ERROR_UPLOAD_CHECK_IMAGE_FAIL : " 检查图片失败",
	ERROR_UPLOAD_CHECK_IMAGE_FORMAT : "校验图片错误，图片格式或大小有问题",
}

/**
获取自定义错误码对应的错误语
 */
func GetMsg(code int) string  {
	msg,ok := MsgFlags[code]
	if ok {
		return msg
	}
	return MsgFlags[ERROR]
}

/**
获取验证器错误提示语
 */
func GetValidMsg(va validation.Validation) (msg string){
	for _,v := range va.Errors {
		msg = v.Message
		break
	}
	return
}
